package com.heipi.myjavademo.布隆过滤器;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.nio.charset.Charset;

/**
 * @author: honry.guan
 * @create: 2025-08-01 15:41
 **/
public class GuavaTest {
    /**
     * <dependency>
     *     <groupId>com.google.guava</groupId>
     *     <artifactId>guava</artifactId>
     *     <version>32.1.2-jre</version>
     * </dependency>
     *
     */
    @SuppressWarnings("UnstableApiUsage")
    public static void main(String[] args) {
        // 创建布隆过滤器，预计插入100个元素，误判率为0.01
        BloomFilter<String> bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charset.defaultCharset()), 100, 0.01);
        bloomFilter.put("hello");
        bloomFilter.put("world");
        bloomFilter.put("guava");
        System.out.println(bloomFilter.mightContain("hello"));
        System.out.println(bloomFilter.mightContain("world"));
        System.out.println(bloomFilter.mightContain("gg"));
    }
}
